package com.btcode.db.executer;

import java.util.UUID;

/**
 * 嵌套事务控制
 *
 * @author gislin
 */
public class TransactionInfo {

    private String transactionId;

    private Integer transactionIndex;

    public TransactionInfo() {
        this.transactionIndex = 1;
        this.transactionId = UUID.randomUUID().toString();
    }

    public String getTransactionId() {
        return transactionId;
    }

    public Integer getTransactionIndex() {
        return transactionIndex;
    }

    /**
     * 计数器加一
     */
    public Integer addTransactionIndex() {
        this.transactionIndex++;
        return this.transactionIndex;
    }

    /**
     * 计数器减一
     */
    public Integer cutTransactionIndex() {
        this.transactionIndex--;
        return this.transactionIndex;
    }

    public boolean isCommitAble() {
        return this.transactionIndex == 0;
    }

    public String toString() {
        return "[transactionId]:" + transactionId + ",[index]:" + transactionIndex;

    }
}
